#define MAX_BUTTON 128

#define BUTTON_DATA_WORLD		(0)
#define BUTTON_DATA_INTERIOR	(1)
#define BUTTON_DATA_TYPE		(2)

#define BUTTON_TYPE_GEN			(0)
#define BUTTON_TYPE_TP			(1)
#define BUTTON_TYPE_NOTE		(2)

new
	ButtonData[MAX_BUTTON][3],
	ButtonArea[MAX_BUTTON],
	Text3D:ButtonLabel[MAX_BUTTON],
	ButtonString[MAX_BUTTON][128],
	ButtonActive[MAX_BUTTON],
	LinkedButton[MAX_BUTTON];

CreateButton(Float:x, Float:y, Float:z, msg[], world=0, interior=0, label=0, type=0)
{
	new id;
	while(ButtonActive[id])id++;

	ButtonArea[id]=CreateDynamicSphere(x, y, z, 1.0, world, interior);
	if(label)ButtonLabel[id]=CreateDynamic3DTextLabel(msg, YELLOW, x, y, z, 10.0, _, _, 1, world, interior, _, 10.0);
	LinkedButton[id]=-1;
	strcat(ButtonString[id], msg);
	ButtonData[id][BUTTON_DATA_WORLD] = world;
	ButtonData[id][BUTTON_DATA_INTERIOR] = interior;
	ButtonData[id][BUTTON_DATA_TYPE] = type;

	ButtonActive[id]=true;

	return id;
}

LinkTP(bID1, bID2)
{
    LinkedButton[bID1]=bID2;
    LinkedButton[bID2]=bID1;
}

Internal_OnButtonPress(playerid, buttonid)
{
	if(LinkedButton[buttonid] >= 0)
	{
		new
			id = LinkedButton[buttonid],
			Float:x,
			Float:y,
			Float:z;

		Streamer_GetFloatData(STREAMER_TYPE_AREA, ButtonArea[id], E_STREAMER_X, x);
		Streamer_GetFloatData(STREAMER_TYPE_AREA, ButtonArea[id], E_STREAMER_Y, y);
		Streamer_GetFloatData(STREAMER_TYPE_AREA, ButtonArea[id], E_STREAMER_Z, z);

        TogCon(1000, playerid);
		SetPlayerVirtualWorld(playerid, ButtonData[id][BUTTON_DATA_WORLD]);
		SetPlayerInterior(playerid, ButtonData[id][BUTTON_DATA_INTERIOR]);
		SetPlayerPos(playerid, x, y, z);
		Streamer_UpdateEx(playerid, x, y, z, ButtonData[id][BUTTON_DATA_WORLD], ButtonData[id][BUTTON_DATA_INTERIOR]);
	}
	else OnButtonPress(playerid, buttonid);
	return 1;
}

// Extras

SetButtonMessage(buttonid, msg[])
{
	memcpy(ButtonString[buttonid], msg, 0, (128*4));
	PlayerLoop(i)if(bPlayerGameSettings[i]&vMsgBox)TextDrawSetString(MsgBox[i], msg);
}
